<?php 
/*
 module:		礼币充值订单
 create_time:	2022-04-07 20:15:24
 author:		
 contact:		
*/

namespace app\backend\controller;

use app\backend\service\ZhGiftOrderService;
use app\backend\model\ZhGiftOrder as ZhGiftOrderModel;
use think\facade\Db;

class ZhGiftOrder extends Admin {


	/*首页数据列表*/
	function index(){
		if (!$this->request->isAjax()){
			return view('index');
		}else{
			$limit  = $this->request->post('limit', 20, 'intval');
			$offset = $this->request->post('offset', 0, 'intval');
			$page   = floor($offset / $limit) +1 ;

			$where = [];
			$where['a.order_sn'] = $this->request->param('order_sn', '', 'serach_in');
			$where['a.status'] = $this->request->param('status', '', 'serach_in');
			$where['a.gift_b_num'] = $this->request->param('gift_b_num', '', 'serach_in');
            $where['a.wxapp_id'] = session('backend.wxapp_id');
            $where['c.name|c.organization_name'] = ['like',$this->request->param('m_name', '', 'serach_in')];
			$order  = $this->request->post('order', '', 'serach_in');	//排序字段 bootstrap-table 传入
			$sort  = $this->request->post('sort', '', 'serach_in');		//排序方式 desc 或 asc
            
            $field = 'a.*,b.real_name,b.nickname,b.matchmaker_id,c.name,c.organization_name,c.is_personal';
			$orderby = ($sort && $order) ? $sort.' '.$order : 'a.id desc';

			$res = ZhGiftOrderService::indexList(formatWhere($where),$field,$orderby,$limit,$page);
			return json($res);
		}
	}

	/*查看详情*/
	function view(){
		$id = $this->request->get('id','','serach_in');
		if(!$id) $this->error('参数错误');
		$sql = 'select a.*,b.nickname from gc_zh_gift_order as a left join gc_member as b on a.u_id=b.uid  where a.id = '.$id.' limit 1';
		$info = Db::connect('mysql')->query($sql);
		
		$this->view->assign('info',current($info));
		return view('view');
	}



}

